package 医院设置;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int N = 110, M = 2 * N, idx;
    static int[] cnt = new int[N];
    static int[] h = new int[N];
    static int[] e = new int[M];
    static int[] ne = new int[M];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Arrays.fill(h, -1);
        for (int i = 1; i <= n; i++) {
            cnt[i] = in.nextInt();
            int l = in.nextInt();
            int r = in.nextInt();
            if (l > 0) {
                add(i, l);
                add(l, i);
            }
            if (r > 0) {
                add(i, r);
                add(r, i);
            }
        }
        int res = 0x3f3f3f3f;
        for (int i = 1; i <= n; i++) {
            res = Math.min(res, dfs(i, -1, 0));
        }
        System.out.println(res);
    }

    private static int dfs(int u, int father, int dist) {
        int sum = dist * cnt[u];
        for (int i = h[u]; i != -1; i = ne[i]) {
            int j = e[i];
            if (j == father) {
                continue;
            }
            sum += dfs(j, u, dist + 1);
        }
        return sum;
    }

    private static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}